home *** CD-ROM | disk | FTP | other *** search
- `=========================
- `Simple Drum Machine
- ` By Andrew Pye
- ` 28/12/2000
- `andrew.pye@ukgateway.net
- ` Created With Dark Basic
- ` Simple Power
- `=========================
- restart:
- `===================
- `SET UP OUR VARIBLES
- `===================
- BANKS=9
- PATTSTEPS=16
- CHANNELS=8
- BPM=130
- CURRENTCHANNEL=1
- CURRENTBANK=1
- BAR=0
- SongLength=255
- Song_Bar=1
- Song_Pattern=1
- Song_Loop=1
-
- `==========================
- `create our pattern storage
- `==========================
- dim PatternStore((PATTSTEPS*BANKS),CHANNELS)
-
- `===============================
- `Create our storage for the song
- `===============================
- dim Song(SongLength-1)
- for i=0 to SongLength-1
- song(i)=Song_Pattern
- next i
-
- `==================
- `CREATE THE DISPLAY
- `==================
- set display mode 640,480,16
-
- `==================================
- `LOAD IN THE SOUNDS FORTHE CHANNELS
- `==================================
- load sound "DRUMB.wav",1
- load sound "crashsymble.WAV",2
- load sound "HAT.wav",3
- load sound "lTom.WAV",4
- load sound "rimshot.WAV",5
- load sound "snare.WAV",6
- load sound "clap.WAV",7
- load sound "bass.wav",8
-
- `==================
- `CREATE THE DIAPLAY
- `==================
- set display mode 640,480,16
- load bitmap "Keyboard.bmp",1
- load bitmap "Clear.bmp",2
-
- SET CURRENT BITMAP 0
- COPY BITMAP 1,0
- set CURRENT BITMAP 0
-
- `========================
- `MAKE SO IT DOES NOT PLAY
- `========================
- PLAYFLAG=0
- CURRENTBANK=1
- PLAYFLAG=0
-
- `===============
- `gosub Drawlight
- `===============
- gosub UpdateDisplay
-
- `======================================
- `this is to speed up the button display
- `======================================
- create bitmap 3,320,240
- load bitmap "buttons.bmp",3
- copy bitmap 3,0,0,319,239,0,200,210,520,450
- set CURRENT BITMAP 0
-
-
- `==============
- `store the time
- `==============
- storetime=timer()
-
- do
- `=======================================
- `Do a check to see if S has been pressed
- `=======================================
- `Save
- if scancode()=31
- GOSUB save
- COPY BITMAP 1,0
- set CURRENT BITMAP 0
- copy bitmap 3,0,0,319,239,0,200,210,520,450
- gosub UpdateDisplay
- gosub Drawlight
- endif
- `lOAD
- if scancode()=38
- GOSUB load
- COPY BITMAP 1,0
- set CURRENT BITMAP 0
- copy bitmap 3,0,0,319,239,0,200,210,520,450
- gosub UpdateDisplay
- gosub Drawlight
- endif
- `new
-
- if PLAYFLAG>0
- if timer()=>storetime+(230-bpm)
- `==============
- `PLAY THE TRACK
- `==============
- TCount=(CHANNELS-1)
- for i=0 to TCount
- if PatternStore(bar+(PATTSTEPS*(CURRENTBANK-1)),i)=1
- play sound (i+1)
- endif
- next i
- `==========
- `store time
- `==========
- storetime=timer()
-
- `==============
- `CHECK THE BAR
- `==============
- IF BAR=15
- BAR=0
- `=========================
- `THIS CREATES THE THE SONG
- `=========================
- IF PLAYFLAG=2
- IF Song_Bar>=SongLength or Song_Bar>=Song_Loop
- Song_Bar=1
- ELSE
- INC Song_Bar
- ENDIF
- CURRENTBANK=SONG(Song_Bar-1)
- ENDIF
-
- ELSE
- INC BAR
- ENDIF
- ENDIF
- ENDIF
- if mouseclick()=1
- `=======
- `tempo +
- `=======
- if buttonid=3
- if bpm<300
- inc bpm
- gosub UpdateDisplay
- endif
- buttonid=0
- endif
-
- `=======
- `tempo -
- `=======
- if buttonid=4
- if bpm>100
- dec bpm
- gosub UpdateDisplay
- endif
- buttonid=0
- endif
- endif
- `=======================================
- `HERE WE CHECK FOR CONTROLS BEEN PRESSED
- `=======================================
- if MOUSECLICK()=0 then ButtonFlag=0
- IF MOUSECLICK()=1
- if ButtonFlag=0
- ButtonFlag=1
- ButtonID=buttonpress(mousex(),mousey())
- `===========================
- `now lets process the result
- `===========================
- `====
- `play
- `====
- if buttonid=1 then PLAYFLAG=1
-
- `====
- `stop
- `====
- if buttonid=2
- PLAYFLAG=0
- bar=0
- endif
-
-
-
- `===============
- `Pattern Buttons
- `===============
- if buttonid=5
- `===========================================
- `a frew maths to get the button been pressed
- `===========================================
- col = Int(mouseX() / 20) -9
- row = Int(mousey() / 30) - 6
- selchannel=row-1
- gosub singlelight
- endif
-
- `============
- `bank buttons
- `============
- if buttonid>5 and buttonid<15
- CURRENTBANK=buttonid-5
- gosub Drawlight
- gosub UpdateDisplay
- endif
-
- `========
- `song bar +
- `========
- if buttonid=15
- if Song_Bar<255
- inc Song_Bar
- Song_Pattern=SONG(Song_Bar-1)
- gosub UpdateDisplay
- endif
- endif
-
- `========
- `song bar -
- `========
- if buttonid=16
- if Song_Bar>1
- dec Song_Bar
- Song_Pattern=SONG(Song_Bar-1)
- gosub UpdateDisplay
- endif
- endif
-
- `============
- `SONG PATTER+
- `============
- if buttonid=17
- if Song_Pattern<9
- inc Song_Pattern
- SONG(Song_Bar-1)=Song_Pattern
- gosub UpdateDisplay
- endif
- endif
-
- `============
- `SONG PATTER-
- `============
- if buttonid=18
- if Song_Pattern>1
- dec Song_Pattern
- SONG(Song_Bar-1)=Song_Pattern
- gosub UpdateDisplay
- endif
- endif
-
- `=========
- `play song
- `=========
- if buttonid=19
- Song_Bar=1
- bar=0
- PLAYFLAG=2
- CURRENTBANK=SONG(Song_Bar-1)
- gosub UpdateDisplay
- endif
- `======
- `Loop +
- `======
- if buttonid=20
- if Song_Pattern<255
- inc song_loop
- gosub UpdateDisplay
- endif
- endif
-
- `======
- `Loop +
- `======
- if buttonid=21
- if Song_Pattern>1
- dec song_loop
- gosub UpdateDisplay
- endif
- endif
-
- endif
- endif
- loop
-
- `=================
- `draw single light
- `=================
- singlelight:
- if PatternStore((col-1)+(PATTSTEPS*(CURRENTBANK-1)),row-1)=1
- PatternStore((col-1)+(PATTSTEPS*(CURRENTBANK-1)),row-1)=0
- ink rgb(0,255,0),rgb(0,255,0)
- else
- PatternStore((col-1)+(PATTSTEPS*(CURRENTBANK-1)),row-1)=1
- ink rgb(255,0,0),rgb(255,0,0)
- endif
- ypos#=217+(30*selchannel)
- xpos#=((col-1)*20)+200
- circle xpos#+11,ypos#,2
- return
-
-
- `==========
- `draw light
- `==========
- Drawlight:
- copy bitmap 3,0,0,319,239,0,200,210,520,450
- set CURRENT BITMAP 0
- for j=0 to 7
- for i=0 to 15
-
- if PatternStore(i+(PATTSTEPS*(CURRENTBANK-1)),j)=1
- ink rgb(255,0,0),rgb(255,0,0)
- xpos#=(i*20)+200
- ypos=217+(30*j)
- circle xpos#+11,ypos,2
- endif
-
-
-
- next i
- next j
-
- return
-
-
- `============================================
- `This is where we redraw all the display info
- `============================================
- UpdateDisplay:
- `set the ink color
- ink rgb(255,0,0),rgb(255,0,0)
- `clear the displays
- `tempo
- COPY BITMAP 2,0,0,58,29,0,80,45,138,74
- `song bar
- COPY BITMAP 2,0,0,58,29,0,480,75,538,104
- `song pattern
- COPY BITMAP 2,0,0,58,29,0,480,135,538,164
- `Bank
- COPY BITMAP 2,0,0,58,29,0,358,120,416,149
- `Loop
- `COPY BITMAP 2,0,0,58,29,0,580,135,638,164
- COPY BITMAP 2,0,0,38,29,0,580,135,618,164
-
- `Tempo
- set cursor 91,53
- print bpm
- `Bank
- set cursor 375,130
- print CURRENTBANK
- `song bar
- set cursor 493,82
- print Song_Bar
- `song pattern
- set cursor 493,143
- print Song_Pattern
- `Loop
- set cursor 590,143
- print Song_Loop
- return
-
- `==========================================
- `this will check if button has been pressed
- `==========================================
- function buttonpress(x,y)
- `================
- `restore the data
- `================
- restore
- `=========
- `SCAN LOOP
- `=========
- result = 0
- for i=1 to 21
- read x1
- read x2
- read y1
- read y2
-
- `===========================
- `HAS THE BUTTON BEEN PRESSED
- `===========================
- if x>=x1 and x<=x2 and y>=y1 and y<=y2
- `button pressed
- result=i
- endif
- next i
- `===========
- `BUTTON DATA
- `===========
- `PLAY STOP
- DATA 60,160,105,134
- DATA 60,160,151,179
- `tempo up down
- data 160,180,46,59
- data 160,180,60,73
- `track1 buttons
- data 200,520,210,450
- `bank buttons 6
- data 320,360,30,60
- data 360,400,30,60
- data 400,440,30,60
-
- data 320,360,60,90
- data 360,400,60,90
- data 400,440,60,90
-
- data 320,360,90,120
- data 360,400,90,120
- data 400,440,90,120
- `song bits
- data 460,480,75,90
- data 460,480,90,105
-
- data 460,480,135,149
- data 460,480,149,165
-
- data 560,620,75,105
-
- `loop
- data 560,580,135,149
- data 560,580,149,165
-
- endfunction result
-
- save:
- `=============
- `Save function
- `=============
-
- ink rgb(155,155,155),rgb(0,0,0)
-
- start:
- rem Clear the screen
- cls
-
- rem List files within checklist
- perform checklist for files
- print "Files in directory:"
- for t=1 to checklist quantity()
- tstr$=checklist string$(t)
- if right$(tstr$,3)="DRM"
- print checklist string$(t)
- endif
- next t
-
- print
-
- input "Save: ",name$
-
- cls
-
- if file exist(name$ +".DRM")=1
- set cursor 220,200
- input "Over write File (Y/N) " + name$ + " :",res$
- if res$="Y" or res$="y"
- delete file name$ +".DRM"
- else
- goto qend
- endif
- endif
-
- cls
- set cursor 320,200
- Print "Saveing..."
- `=====================
- `Open file for reading
- `=====================
- open to write 1,name$ +".DRM"
-
- for i=0 to 254
- tbyte=song(i)
- write byte 1,tbyte
- next i
- `save pattern
- for i=0 to (16*9)
- for j=0 to 8
- write byte 1,PatternStore(i,j)
- next j
- next i
- write byte 1,BPM
- WRITE BYTE 1,Song_Loop
- close file 1
- qend:
-
- RETURN
-
-
- load:
- `=============
- `load function
- `=============
- ink rgb(155,155,155),rgb(0,0,0)
- start2:
- rem Clear the screen
- cls
- rem List files within checklist
- perform checklist for files
- print "Files in directory:"
- for t=1 to checklist quantity()
- tstr$=checklist string$(t)
- if right$(tstr$,3)="DRM"
- print checklist string$(t)
- endif
- next t
- print
- input "Load: ",name$
- cls
-
- if file exist(name$ + ".drm")=1
- set cursor 320,200
- Print "Loading..."
- `=====================
- `Open file for reading
- `=====================
- open to read 1,name$ + ".DRM"
-
- for i=0 to 254
- read BYTE 1,tbyte
- song(i)= tbyte
- next i
- `save pattern
- for i=0 to (16*9)
- for j=0 to 8
- read byte 1,tbyte
- PatternStore(i,j)=tbyte
- next j
- next i
-
- read byte 1,BPM
- read byte 1,Song_Loop
- close file 1
- else
- set cursor 220,200
- Print "Error Canno't Find File " + name$
- set cursor 220,220
- Print "Press Key To Continue..."
- suspend for key
- ` goto start2
- endif
-
- RETURN
-